package cn.tedu.charging.redis.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;

@Configuration
public class RedisCustConfig {
    //覆盖 底层配置类 创建的RedisTemplate
    @Bean("redisTemplate")
    public RedisTemplate redisInit(RedisConnectionFactory redisConnection){
        //在一个@Bean的方法中 需要入参 会从容器寻找
        //新建redisTemplate 自定义对象序列化 key value
        RedisTemplate redisTemplate=new RedisTemplate();
        redisTemplate.setConnectionFactory(redisConnection);
        redisTemplate.setKeySerializer(RedisSerializer.string());
        redisTemplate.setValueSerializer(RedisSerializer.string());
        //field
        redisTemplate.setHashKeySerializer(RedisSerializer.string());
        //value
        redisTemplate.setHashValueSerializer(RedisSerializer.string());
        return redisTemplate;
    }
}
